<?php 
namespace Admin\Controller;
use Think\Controller;
use Admin\Builder\AdminConfigBuilder;
use Admin\Builder\AdminListBuilder;

class SchoolController extends Controller{
	public $courseLevel=array(0=>"普通",1=>"VIP",2=>"全包",3=>"老手");
	//合作商列表
	public function Partner($page=1,$r=15){
		
		if(I('channelNo')){
			$map['channelNo']=I("channelNo");
		}
		if(I('username')){
			$map['username']=I("username");
		}
		if(I('sellname')){
			$map['sellname']=I("sellname");
		}
		if(I('mobile')){
			$map['mobile']=I("mobile");
		}
		if(I('channelName')){
			$map['channelName']=I("channelName");
		}
		
		$list=M("partner")->where($map)->page($page,$r)->order("addtime desc")->select();
		foreach($list as $k=>$v){
			$list[$k]['bank']=$v['bankNo']."【".$v['bankName']."】";
			
			$imgEwmUrl=C("BaseUrl")."/index.php?s=/School/index/channelQrcode/channelNo/".$v['channelNo'];
			
			$list[$k]['ewm']=$imgEwmUrl;
		}
		//print_r($list);exit;
		$totalCount=M("partner")->where($map)->count();
		$builder=new AdminListBuilder();
		$builder->title("合作商列表");
		$builder->ButtonNew(U('partnerInfo'));
		
		$builder->search("渠道代码","channelNo");
		$builder->search("联系人","username");
		$builder->search("销售","sellname");
		$builder->search("联系电话","mobile");
		$builder->search("渠道商","channelName");
		
		$builder->keyId();
		$builder->keyText("channelName","渠道商");
		$builder->keyText("channelNo","渠道代码");
		$builder->keyText("username","联系人");
		$builder->keyText("sellname","销售");
		$builder->keyText("mobile","联系电话");
		$builder->keyText("preferential_vip","VIP优惠");
		$builder->keyText("charges_vip","VIP佣金");
		$builder->keyText("preferential_all","全包班优惠");
		$builder->keyText("charges_all","全包班佣金");
		$builder->keyText("preferential_old","老手班优惠");
		$builder->keyText("charges_old","老手班佣金");
		$builder->keyText("bank","银行");
		$builder->keyText("alipayNo","支付宝");
		$builder->keyText("addtime","创建时间");
		$builder->keyImage("ewm","渠道二维码");
		$builder->keyText("money","佣金");
		$builder->keyDoAction('partnerInfo?id=###', '修改');
		$builder->data($list);
		$builder->pagination($totalCount,$r);
		$builder->display();
	}
	//新增合作商
	public function partnerInfo(){
		if(IS_POST){
			//密码加密
			$post=I();
			if(!$post['password']){
				$post['password']=123456;
			}
			$post['password']=encrypt($post['password']);
			$post['addtime']=date("Y-m-d H:i:s",$post['addtime']);
			
			//判断是否存在电话号码
			//$post['channelNo']=$param = str_pad(mt_rand(0, 999999), 6, "0", STR_PAD_BOTH);
			if(!$post['id']){		
				$r=M("partner")->add($post);
				$id=$r;
				
				//更新渠道代码
				$len=strlen($id);
				for($i=0;$i<6-$len;$i++){
					$lt.=mt_rand(1, 9);
				}
				$channelNo=$lt.$id;
				$r=M("partner")->where("id='".$id."'")->save(array("channelNo"=>$channelNo));
				
			}else{
				$map=array();
				$map['id']=$post['id'];
				unset($post['id']);
				$r=M("partner")->where($map)->save($post);
				if(!$r){
					$this->success("保存成功",U("Partner"));
				}
			}
			
			if($r){
				$this->success("保存成功",U("Partner"));
			}else{
				$this->error("保存失败");
			}
		}else{
			$map=array();
			$map['id']=I("id");
			$data=M("partner")->where($map)->find();
			$data['addtime']=strtotime($data['addtime']);
			$builder=new AdminConfigBuilder();
			$builder->title("合作商信息");
			$builder->keyId();
			$builder->keyText("channelName","渠道商");
			$builder->keyText("sellname","销售");
			$builder->keyReadOnly("channelNo","渠道代码","渠道代码为自动生成，随机不重复6位数");
			$builder->keyText("username","联系人");
			$builder->keyText("mobile","联系电话");
			$builder->keyText("preferential_vip","VIP优惠");
			$builder->keyText("charges_vip","VIP佣金");
			$builder->keyText("preferential_all","全包班优惠");
			$builder->keyText("charges_all","全包班佣金");
			$builder->keyText("preferential_old","老手班优惠");
			$builder->keyText("charges_old","老手班佣金");
			$builder->keyText("bankName","开户行");
			$builder->keyText("bankNo","银行账号");
			$builder->keyText("alipayNo","支付宝");
			$builder->keyText("money","佣金");
			$builder->keyText("","密码","默认密码为123456");
			$builder->keyTime("addtime","创建时间","","datetime");
			$builder->data($data);
			$builder->ButtonSubmit();
			$builder->buttonBack();
			$builder->display();
		}
	}
	//微信玩家列表
	public function wxuser($page=1,$r=15){
		
		if(I('nickname')){
			$map['a.nickname']=I("nickname");
		}
		if(I('name')){
			$map['a.name']=I("name");
		}
		if(I('mobile')){
			$map['a.mobile']=I("mobile");
		}
		if(I('channelNo')){
			$map['a.channelNo']=I("channelNo");
		}
		
		$list=M("student_wx a")->join("__PARTNER__ b on a.channelNo=b.channelNo","left")->
		field("a.*,b.channelName")->where($map)->page($page,$r)->order("addtime desc")->select();
		$totalCount=M("student_wx a")->where($map)->count();
		foreach($list as $k=>$v){
			$map=array();
			$map['uid']=$v['id'];
			$haveOrder=D("trade")->where($map)->find();
			if($haveOrder){
				$list[$k]['haveOrder']=1;
			}else{
				$list[$k]['haveOrder']=0;
			}
		}
		
		$builder=new AdminListBuilder();
		$builder->title("意向用户列表");
		$builder->ButtonNew(U('wxuserInfo'));
		$builder->keyId();
		$builder->search("姓名","name");
		$builder->search("昵称","nickname");
		$builder->search("电话","mobile");
		$builder->search("渠道代码","channelNo");
		
		$builder->keyText("nickname","昵称");
		$builder->keyText("name","姓名");
		$builder->keyText("mobile","联系电话");
		$builder->keyText("channelNo","渠道代码");
		$builder->keyText("channelName","渠道销售");
		$builder->keyText("addtime","登记时间");
		$builder->keyMap("haveOrder","下单状态",array(0=>"未下单",1=>"已下单"));
		$builder->keyDoAction('wxuserInfo?id=###', '修改');
		
		$builder->data($list);
		$builder->pagination($totalCount,$r);
		$builder->display();
		
	}
	//修改意向客户信息
	public function wxuserInfo(){
		$map['id']=I('id');
		$info=M("student_wx")->where($map)->find();
		if(IS_POST){
			$post=I();
			$post['addtime']=date("Y-m-d H:i:s",$post['addtime']);
			
			if(I("id")){
				$r=M("student_wx")->where($map)->save($post);
			}else{
				$r=M("student_wx")->add();
			}
			if($r){
				$this->success("保存成功",U("wxuser"));
			}else{
				$this->error("保存失败");
			}
		}else{
			$info['addtime']=strtotime($info['addtime']);
			$builder=new AdminConfigBuilder();
			$builder->title("意向客户信息");
			$builder->keyId();
			$builder->keyText("nickname","昵称");
			$builder->keyText("name","姓名");
			$builder->keyText("mobile","联系电话");
			$builder->keyText("channelNo","渠道代码");
			$builder->keyTime("addtime","登记时间");
			//$builder->keyMap("haveOrder","下单状态",array(0=>"未下单",1=>"已下单"));
			$builder->buttonSubmit();
			$builder->buttonBack();
			$builder->data($info);
			$builder->display();
		}
	}	

	//课程列表
	public function courselist($page=1,$r=15){
		
		$list=M("course")->where($map)->page($page,$r)->order("addtime desc")->select();
		$totalCount=M("course")->where($map)->count();
		$builder=new AdminListBuilder();
		$builder->title("课程列表");
		$builder->ButtonNew(U("courseInfo"));
		
		$builder->keyId();
		$builder->keyText("name","课程名称");
		$builder->keyText("area","课程分区");
		$builder->keyText("content","课程内容");
		$builder->keyText("price","课程价格");
		$builder->keyImage("img","课程图片");
		$builder->keyMap("level","课程类别",$this->courseLevel);
		$builder->keyDoAction("courseInfo?id=###","课程详情");
		
		$builder->data($list);
		$builder->pagination($totalCount);
		$builder->display();
		
	}
	//课程信息
	public function courseInfo(){
		
		if(IS_POST){
			$post=I();
			$post['addtime']=date("Y-m-d H:i:s",$post['addtime']);
			if(!$post['id']){
				$r=M("course")->add($post);
			}else{
				$map=array();
				$map['id']=$post['id'];
				unset($post['id']);
				$r=M("course")->where($map)->save($post);
				if(!$r){
					$this->success("保存成功",U("courselist"));
				}
			}
			if($r){
				$this->success("保存成功",U("courselist"));
			}else{
				$this->error("保存失败");
			}
		}else{
			$map=array();
			$map['id']=I("id");
			$data=M("course")->where($map)->find();
			$data['addtime']=strtotime($data['addtime']);
			$builder=new AdminConfigBuilder();
			$builder->title("课程信息");
			$builder->keyId();
			$builder->keyText("name","课程名称");
			$builder->keyText("area","课程分区");
			$builder->keySelect("level","课程类别","",$this->courseLevel);
			$builder->keyText("price","课程价格");
			$builder->keySingleImage("img","课程图片");
			$builder->keyTextArea("content","课程内容");
			$builder->keyEditor("detail","课程详情");
			$builder->keyTime("addtime","创建时间","","datetime");
			$builder->keyText("top","排序","数字越大越排到前面");
			$builder->data($data);
			$builder->ButtonSubmit();
			$builder->buttonBack();
			$builder->display();
		}
		
	}
	
	/**
	 * tradelist 订单列表
	 */
	public function tradelist($page=1,$r=15){
		
		$start_time=I("start_time");
		$end_time=I("end_time");
		
		if($start_time&&$end_time){
			$map['create_time']=array("BETWEEN",array($start_time,$end_time));
		}else if($start_time){
			$map['create_time']=array('egt',$start_time);
		}else if($end_time){
			$map['create_time']=array('elt',$start_time);
		}else{
			$map=array();
		}
		if(I('course_name')){
			$map['course_name']=I("course_name");
		}
		if(I('uid')){
			$map['uid']=I("uid");
		}
		if(I('status')){
			$map['status']=I("status");
			if($map['status']==999){
				unset($map['status']);
			}
		}
		
		
		$list=M("trade")->where($map)->page($page,$r)->order("createtime desc")->select();
		/* foreach($list as $k=>$v){
			
			$list[$k]['bank']=$v['bankNo']."【".$v['bankName']."】";
			
			$imgEwmUrl=C("BaseUrl")."/index.php?s=/School/index/channelQrcode/channelNo/".$v['channelNo'];
			
			$list[$k]['ewm']=$imgEwmUrl;
		} */
		$totalCount=M("trade")->where($map)->count();
		
		$map['status']=array('egt',0);
		$taotalSum=M("trade")->field("sum(paymoney_1) num1,sum(paymoney_2) num2 ")->where($map)->select();
		
		$builder=new AdminListBuilder();
		$builder->title("订单列表");
		
		$builder->keyId();
		$builder->search("课程名","course_name");
		$builder->search("学员id","uid");
		$builder->search("开始时间","start_time","datetime");
		$builder->search("结束时间","end_time","datetime");
		
		$builder->panel("已付单总额",$taotalSum['num1']+$taotalSum['num2']);
		
		$builder->buttonDiy(U("tradelist"),"清空搜索");
		
		$typeselect[]=array("id"=>999,"value"=>"全部");
		$typeselect[]=array("id"=>0,"value"=>"未支付");
		$typeselect[]=array("id"=>1,"value"=>"已支付首期");
		$typeselect[]=array("id"=>2,"value"=>"已支付全款");
		
		$builder->select("订单状态","status",'select','','','',$typeselect);
		
		$builder->keyText("course_name","课程名");
		$builder->keyText("uid","学员id");
		$builder->keyText("createtime","创建时间");
		$builder->keyText("price","订单金额");
		$builder->keyText("coupon_price","优惠金额");
		$builder->keyMap("type","付款形式",array(1=>"全款",0=>"二期"));
		$builder->keyMap("paytype","支付方式",array(0=>"线下",1=>"微信"));
		$builder->keyText("paymoney_1","一期付款金额","如果不分期，这里就是总款");
		$builder->keyText("paymoney_2","尾款");
		$builder->keyMap("status","订单状态",array(0=>"未支付",1=>"已支付收款",2=>"已全支付"));
		$builder->keyDoAction('tradeInfo?id=###', '修改');
		$builder->keyDoAction('studentInfo?id=###', '核实学员资料');
		$builder->keyDoAction('tradecomplete?id=###', '结束订单并分佣');
		$builder->data($list);
		$builder->pagination($totalCount,$r);
		$builder->display();
	}
	/**
	 * 订单修改
	 */
	public function tradeInfo(){
		$map['id']=I("id");
		$tradeinfo=M("trade")->where($map)->find();
		if(IS_POST){
			$param=I();
			if($tradeinfo){
				unset($param['id']);
				$r=M("trade")->where($map)->save($param);
				
			}
			
		}else{
			$builder=new AdminConfigBuilder();
			$builder->title("订单列表");
			
			$builder->keyId();
			$builder->keyText("course_id","课程id");
			$builder->keyText("course_name","课程名");
			$builder->keyLabel("uid","学员id");
			$builder->keyText("createtime","创建时间");
			$builder->keyText("price","订单金额");
			$builder->keyText("coupon_id","优惠券ID");
			$builder->keyText("coupon_price","优惠金额");
			$builder->keySelect("type","付款形式","",array(1=>"全款",0=>"二期"));
			$builder->keySelect("paytype","支付方式","",array(0=>"线下",1=>"微信"));
			$builder->keyText("paymoney_1","一期付款金额","如果不分期，这里就是总款");
			$builder->keyText("paymoney_2","尾款");
			//$builder->keySelect("status","订单状态","",array(0=>"未支付",1=>"已支付收款",2=>"已全支付"));
			$builder->buttonSubmit();
			$builder->buttonBack();
			$builder->data($tradeinfo);
			$builder->display();
			
		}
	}
	
	/**
	 *  学员资料
	 */
	public function studentInfo(){
		$map['id']=I('id');
		$tradeinfo=M("trade")->where($map)->find();
		$student_info=M("student_info")->where("uid='".$tradeinfo['uid']."'")->find();
		
		$builder=new AdminConfigBuilder();
		$builder->title("学员资料");
			
		$builder->keyId();
		$builder->keyText("name","姓名");
		$builder->keyText("course_name","课程名");
		$builder->keyText("identify","身份证号");
		$builder->keyText("identify_addr","身份证地址");
		$builder->keySelect("gender","性别","",array(1=>"男",0=>"女"));
		$builder->keySelect("have_mb","是否有摩托车驾照","",array(1=>"有",0=>"无"));
		$builder->keySelect("join_school","是否有报名其他驾校","",array(1=>"有",0=>"无"));
		$builder->keyText("mobile","手机号码");
		$builder->keyText("height","身高");
		$builder->keySelect("is_shortsignted","是否近视","",array(0=>"否",1=>"是"));
		$builder->keyText("address","地区");
		$builder->keySelect("contract","合同签订","",array(0=>"否",1=>"是"));
		$builder->keyText("addtime","提交时间");
		//$builder->keySelect("status","订单状态","",array(0=>"未支付",1=>"已支付收款",2=>"已全支付"));
		$builder->buttonSubmit();
		$builder->buttonBack();
		$builder->data($student_info);
		$builder->display();
	}
	/**
	 * 结束订单
	 */
	public function tradecomplete(){
		$map['id']=I('id');
		$tradeinfo=M("trade")->where($map)->find();
		$model=M();
		$model->startTrans();
		$r1=$model->table("qy_trade")->where($map)->save(array("status"=>2));
		//分佣
		$partner=D("Student")->getStudentChannel($tradeinfo['uid']);
		
		$money=D("Partner")->getFenyongMoney($tradeinfo['id']);
		if($money>0){
			$r2=1;
		}
		
		if($partner&&$money>0){
			$r2=$model->table("qy_partner")->where("id='".$partner['id']."'")->setInc("money",$money);
		}
		
		//记录
			$param["money"]=$money;
			$param['tradeid']=$tradeinfo['id'];
			$param['channelNo']=$partner['channelNo'];
			$param['partnerid']=$partner['id'];
			$param['addtime']=date("Y-m-d H:i:s",time());
			$param['from_uid']=$tradeinfo['uid'];
			$param['type']=1;
			$param['remark']="订单返佣";
			$r3=$model->table("qy_fenxiao_log")->add($param);
		/* echo "r1:".$r1."<br/>";
		echo "r2:".$r2."<br/>";
		echo "r3:".$r3."<br/>";
		exit; */
		if($r1&&$r2&&$r3){
			$model->commit();
			$this->success("订单结束成功");
		}else{
			$model->rollback();
			$this->error("订单结束失败");
		}
		
	}
	/**
	 * 优惠券信息
	 */
	public function couponlist($page=1,$r=15){

		
		$list=M("coupon a")->field("a.*,b.nickname")->join("__STUDENT_WX__ b on a.uid=b.id")->where($map)->page($page,$r)->order("createtime desc")->select();
		$totalCount=M("coupon")->where($map)->count();
		$builder=new AdminListBuilder();
		$builder->title("领取的优惠券");
		$builder->keyId();
		$builder->keyText("channelNo","渠道代号");
		$builder->keyText("uid","客户id");
		$builder->keyText("nickname","客户昵称");
		$builder->keyText("createtime","创建时间");
		$builder->keyMap("status","使用情况",array(1=>"已使用",0=>"未使用"));
		$builder->data($list);
		$builder->pagination($totalCount,$r);
		$builder->display();
		
	}
	/**
	 * 分佣记录
	 */
	public function fenyong(){
		
		$start_time=I("start_time");
		$end_time=I("end_time");
		
		if($start_time&&$end_time){
			$map['a.addtime']=array("BETWEEN",array($start_time,$end_time));
		}else if($start_time){
			$map['a.addtime']=array('egt',$start_time);
		}else if($end_time){
			$map['a.addtime']=array('elt',$start_time);
		}else{
			$map=array();
		}
		if(I('sellname')){
			$map['b.sellname']=I("sellname");
		}
		if(I('tradeid')){
			$map['tradeid']=I("tradeid");
		}
		if(I('channelNo')){
			$map['a.channelNo']=I("channelNo");
		}
		
		$list=M("fenxiao_log a")->field("a.*,b.sellname")->join("__PARTNER__ b on a.partnerid=b.id")->where($map)->page($page,$r)->order("a.addtime desc")->select();
		$totalCount=M("fenxiao_log a")->where($map)->count();
		
		$taotalSum=M("fenxiao_log a")->field("sum(money) num")->where($map)->select();
		$builder=new AdminListBuilder();
		$builder->title("分佣记录");
		
		$builder->search("销售","sellname");
		$builder->search("订单号","tradeid");
		$builder->search("渠道代号","channelNo");
		
		$builder->search("开始时间","start_time","datetime");
		$builder->search("结束时间","end_time","datetime");
		$builder->panel("分佣总额",$taotalSum['num']);
		$builder->keyId();
		$builder->keyText("sellname","销售");
		$builder->keyText("tradeid","订单号");
		$builder->keyText("channelNo","渠道代号");
		$builder->keyText("addtime","分佣时间");
		$builder->keyText("from_uid","客户id");
		$builder->data($list);
		$builder->pagination($totalCount,$r);
		$builder->display();
		
	}
	
	//考试管理
	public function examList(){

		$start_time=I("start_time");
		$end_time=I("end_time");
		
		if($start_time&&$end_time){
			$map['examDate']=array("BETWEEN",array($start_time,$end_time));
		}else if($start_time){
			$map['examDate']=array('egt',$start_time);
		}else if($end_time){
			$map['examDate']=array('elt',$start_time);
		}else{
			$map=array();
		}
		if(I('title')){
			$map['title']=array("like","%".I("title")."%");
		}
		if(I('uid')){
			$map['uid']=I("uid");
		}
		if(I('status')){
			$map['status']=I("status");
			if($map['status']==999){
				unset($map['status']);
			}
		}
		if(I('status')){
			$map['status']=I("status");
		}
		
		$list=M("exam")->where($map)->page($page,$r)->order("examDate desc")->select();
		/* foreach($list as $k=>$v){
		 	
		$list[$k]['bank']=$v['bankNo']."【".$v['bankName']."】";
			
		$imgEwmUrl=C("BaseUrl")."/index.php?s=/School/index/channelQrcode/channelNo/".$v['channelNo'];
			
		$list[$k]['ewm']=$imgEwmUrl;
		} */
		$totalCount=M("exam")->where($map)->count();
			
		$builder=new AdminListBuilder();
		$builder->title("考试列表");
		
		$builder->keyId();
		$builder->search("考试名称","title");
		$builder->search("开始时间(考试时间)","start_time","datetime");
		$builder->search("结束时间（考试时间）","end_time","datetime");
		$builder->buttonDiy(U("examList"),"清空搜索");
		$builder->buttonNew(U("examInfo"),"新增");
		
		$typeselect[]=array("id"=>999,"value"=>"全部");
		$typeselect[]=array("id"=>0,"value"=>"未开始");
		$typeselect[]=array("id"=>1,"value"=>"报名中");
		$typeselect[]=array("id"=>2,"value"=>"已结束");
		
		
		$courseSelect[]=array("id"=>0,"value"=>"全部");
		$courseSelect[]=array("id"=>1,"value"=>"科目一");
		$courseSelect[]=array("id"=>2,"value"=>"科目二");
		$courseSelect[]=array("id"=>3,"value"=>"科目三");
		$courseSelect[]=array("id"=>4,"value"=>"科目四");
		$courseSelect[]=array("id"=>5,"value"=>"科目五");
		
		$builder->select("考试状态","status",'select','','','',$typeselect);
		$builder->select("考试科目","type",'select','','','',$courseSelect);
		
		$builder->keyText("title","考试名称");
		$builder->keyText("content","考试内容");
		$builder->keyText("examDate","考试时间");
		$builder->keyText("enterEndDate","报名截止时间");
		$builder->keyText("goDate","出发时间");
		$builder->keyText("enterNum","报名人数限制");
		$builder->keyMap("type","考试科目",array(1=>"科目一",2=>"科目二",3=>"科目三",4=>"科目四",5=>"科目五"));
		$builder->keyMap("status","考试状态",array(0=>"未开始",1=>"报名中",2=>"已结束"));
		$builder->keyDoAction('examInfo?id=###', '修改');
		$builder->keyDoAction('examStudentList?id=###', '报名列表');
		$builder->keyDoAction('examStart?id=###', '开始报名');
		$builder->keyDoAction('examcomplete?id=###', '结束考试');
		$builder->data($list);
		$builder->pagination($totalCount,$r);
		$builder->display();
	}
	//考试信息
	public function examInfo(){
		//$map['id']=I("id");		
		$info=M("exam")->find(I("id"));
		
		if(IS_POST){
			$post=I();
			$post['examDate']=date("Y-m-d H:i:s",$post['examDate']);
			$post['enterEndDate']=date("Y-m-d H:i:s",$post['enterEndDate']);
			$post['goDate']=date("Y-m-d H:i:s",$post['goDate']);
			
			if(!$post['id']){
				$post['status']=0;
				$r=M("exam")->add($post);
			}else{
				$map=array();
				$map['id']=$post['id'];
				unset($post['id']);
				$r=M("exam")->where($map)->save($post);
				if(!$r){
					$this->success("保存成功",U("examList"));
				}
			}
			if($r){
				$this->success("保存成功",U("examList"));
			}else{
				$this->error("保存失败");
			}
		}else{
			$info['examDate']=strtotime($info['examDate']);
			$info['enterEndDate']=strtotime($info['enterEndDate']);
			$info['goDate']=strtotime($info['goDate']);
			$courseType=array(1=>"科目一",2=>"科目二",3=>"科目三",4=>"科目四",5=>"科目五");
			$builder=new AdminConfigBuilder();
			$builder->title("考试信息");
			$builder->keyId();
			$builder->keyText("title","考试名称");
			$builder->keyText("content","考试内容");
			$builder->keyTime("examDate","考试时间","","datetime");
			$builder->keyTime("enterEndDate","报名截止时间","","datetime");
			$builder->keyTime("goDate","出发时间","","datetime");
			$builder->keyText("enterNum","报名人数限制");
			$builder->keySelect("type","考试科目	","",$courseType);
			$builder->keyText("addressPoint","集合地点");
			$builder->keyText("contact","联系人");
			$builder->keyEditor("detail","考试详情");
			
			$builder->data($info);
			$builder->buttonSubmit();
			$builder->buttonBack();
			$builder->display();
		}
	}
	//开始报名
	public function examStart(){
		$id=I("id");
		$r=M("exam")->where("id='".$id."'")->save(array("status"=>1));
		if($r){
			$this->success("修改成功",U("examList"));
		}else{
			$this->error("修改失败",U("examList"));
		}
	}
	//结束报名
	public function examcomplete(){
		$id=I("id");
		$r=M("exam")->where("id='".$id."'")->save(array("status"=>2));
		if($r){
			$this->success("修改成功",U("examList"));
		}else{
			$this->error("修改失败",U("examList"));
		}
	}
}
	
?>